import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * 接口字段维护 服务
 * apiFieldService
 * @date 2019-07-09
 */

/**
 * 接口 model 不能修改
 * @typedef {object} API
 * @property {number} fieldId - 主键
 * @property {string} serviceName - 服务名 Lov
 * @property {string} method - 请求方式 值集
 * @property {string} path - 请求路径
 * @property {number} description - 请求描述
 */

/**
 * @description 字段 model 可以 查增改删
 * @typedef {Object} FIELD
 * @property {number} fieldId - 主键
 * @property {string} fieldDescription - 字段描述 480
 * @property {string} fieldName - 字段名称 120
 * @property {string} fieldType - 字段类型 值集
 * @property {number} orderSeq - 排序
 * @property {number} permissionId - 接口id
 */

/**
 * @typedef {Object} Page<T>
 * @property {number} number - 分页
 * @property {number} size - 分页大小
 * @property {number} totalElements - 总数据量
 * @property {T[]} content - 数据
 */

/**
 * @typedef {Object} PageInfo
 * @property {number} page - 分页
 * @property {number} size - 分页大小
 */
import { CPAAS_IAM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel, parseParameters } from 'utils/utils';
import request from 'utils/request';
/**
 * 查询接口
 * @param params
 * @return {Promise<API[]>}
 */

export function apiFieldApiQuery(_x) {
  return _apiFieldApiQuery.apply(this, arguments);
}
/**
 * 查询对应接口的字段
 * @param {number} permissionId - 接口id
 * @param {PageInfo} params - 查询分页参数
 * @param {FIELD} params - 查询实体
 * @return {Promise<API[]>}
 */

function _apiFieldApiQuery() {
  _apiFieldApiQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var query, reqUrl;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            query = parseParameters(params);
            reqUrl = isTenantRoleLevel() ? "".concat(CPAAS_IAM, "/v1/").concat(getCurrentOrganizationId(), "/apis") : "".concat(CPAAS_IAM, "/v1/apis");
            return _context.abrupt("return", request(reqUrl, {
              method: 'GET',
              query: _objectSpread(_objectSpread({}, query), {}, {
                includeAll: true
              })
            }));

          case 3:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _apiFieldApiQuery.apply(this, arguments);
}

export function apiFieldFieldQuery(_x2, _x3) {
  return _apiFieldFieldQuery.apply(this, arguments);
}
/**
 * 修改对应接口的字段
 * @param {number} permissionId - 接口id
 * @param {FIELD} record - 修改实体
 */

function _apiFieldFieldQuery() {
  _apiFieldFieldQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(permissionId, params) {
    var query, reqUrl;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            query = parseParameters(params);
            reqUrl = isTenantRoleLevel() ? "".concat(CPAAS_IAM, "/v1/").concat(getCurrentOrganizationId(), "/apis/").concat(permissionId, "/fields") : "".concat(CPAAS_IAM, "/v1/apis/").concat(permissionId, "/fields");
            return _context2.abrupt("return", request(reqUrl, {
              method: 'GET',
              query: query
            }));

          case 3:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _apiFieldFieldQuery.apply(this, arguments);
}

export function apiFieldFieldUpdate(_x4, _x5) {
  return _apiFieldFieldUpdate.apply(this, arguments);
}
/**
 * 新增对应接口的字段
 * @param {number} permissionId - 接口id
 * @param {FIELD} record - 修改实体
 */

function _apiFieldFieldUpdate() {
  _apiFieldFieldUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(permissionId, record) {
    var reqUrl;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            reqUrl = isTenantRoleLevel() ? "".concat(CPAAS_IAM, "/v1/").concat(getCurrentOrganizationId(), "/apis/").concat(permissionId, "/fields") : "".concat(CPAAS_IAM, "/v1/apis/").concat(permissionId, "/fields");
            return _context3.abrupt("return", request(reqUrl, {
              method: 'PUT',
              body: record
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _apiFieldFieldUpdate.apply(this, arguments);
}

export function apiFieldFieldCreate(_x6, _x7) {
  return _apiFieldFieldCreate.apply(this, arguments);
}
/**
 * 删除对应接口的字段
 * @param {number} permissionId - 接口id
 * @param {FIELD} record - 修改实体
 */

function _apiFieldFieldCreate() {
  _apiFieldFieldCreate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(permissionId, record) {
    var reqUrl;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            reqUrl = isTenantRoleLevel() ? "".concat(CPAAS_IAM, "/v1/").concat(getCurrentOrganizationId(), "/apis/").concat(permissionId, "/fields") : "".concat(CPAAS_IAM, "/v1/apis/").concat(permissionId, "/fields");
            return _context4.abrupt("return", request(reqUrl, {
              method: 'POST',
              body: record
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _apiFieldFieldCreate.apply(this, arguments);
}

export function apiFieldFieldRemove(_x8, _x9) {
  return _apiFieldFieldRemove.apply(this, arguments);
}

function _apiFieldFieldRemove() {
  _apiFieldFieldRemove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(permissionId, record) {
    var reqUrl;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            reqUrl = isTenantRoleLevel() ? "".concat(CPAAS_IAM, "/v1/").concat(getCurrentOrganizationId(), "/apis/").concat(permissionId, "/fields") : "".concat(CPAAS_IAM, "/v1/apis/").concat(permissionId, "/fields");
            return _context5.abrupt("return", request(reqUrl, {
              method: 'DELETE',
              body: record
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _apiFieldFieldRemove.apply(this, arguments);
}